const db = wx.cloud.database()
// pages/end1/end1.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    "tabs": [
      {
        "mid": 0,
        "name": "志愿",
        "isActive": true
      },
      {
        "mid": 1,
        "name": "社团",
        "isActive": false
      },
      {
        "mid": 2,
        "name": "讲座",
        "isActive": false
      },{
        "mid": 3,
        "name": "自由",
        "isActive": false
      },
    ],

    "card": [], 
    "card_mid":"0",
    "bottom": [{
      id: 0,
      text: "首页",
      selectedIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.0.png?sign=8efcdca8770c182531fd1d0a5b98bee7&t=1621066787",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.1.png?sign=4b58233a9a18aed2b79064b59005387e&t=1621066799",
    }, {
      id: 1,
      text: "活动",
      selectedIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.0.png?sign=012969fbfc15e20d6ae5c4a6c9d67f5a&t=1621066822",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.1.png?sign=837e43574ead133a890d0afe82a79415&t=1621066837",
    }, {
      id: 2,
      text: "收藏",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/8.0.0.png?sign=8a80489dff605f44d9507571a1512f7d&t=1621066859",
      selectedIcon: "",
    }, {
      id: 3,
      text: "我的",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/9.0.1.png?sign=ded7f69596df7b109d7bc7516da3ac2c&t=1621066877",
      selectedIcon: "",
    }],
    card_mid: "0",
    showView1: true,
    showView2: true,
  },

  bottomJump: function (e) {
    // console.log(e.currentTarget.dataset.bottomitemdata)
    if ("首页" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end/end'
      })

    } else if ("活动" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end1/end1'
      })
    } else if ("收藏" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end2/end2'
      })
    } else if ("我的" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end3/end3'
      })
    }
  },

  cardJump: function (e) {
    console.log("carditem_data=",e)
    console.log("shuju",e.currentTarget.dataset.carditem_data)
    getApp().globalData.carditem_data = e.currentTarget.dataset.carditem_data
    wx.navigateTo({
       url: '../../pages/activity/activity'
    })
  },

  tianjiadian: function (e) {
    wx.navigateTo({
      url: '../../pages/end4/end4'
    })
  },
  handleItemchange: function (e) {
    const {index} = e.detail;
    let {tabs} = this.data;
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    this.setData({
      tabs,
      card_mid:index
    })
  },

  onShow: function () {
    var that = this
    db.collection('all').get().then(res => {
      console.log("a卡",res)
      var zhiyuan =[];
      var shetuan =[];
      var jiangzuo =[];
      var ziyou =[];
      var card=[];
      // var mid = that.data.card_mid;
      for(let i = 0;i < res.data.length;i++){
        console.log("空",res.data[i])
        if (res.data[i].mid == 0){
          zhiyuan.push(res.data[i])
        };
        if (res.data[i].mid == 1){
          shetuan.push(res.data[i])
        };
        if (res.data[i].mid == 2){
          jiangzuo.push(res.data[i])
        };
        if (res.data[i].mid == 3){
          ziyou.push(res.data[i])
        }
      }
      if (zhiyuan !== null){
        card.push(zhiyuan,shetuan,jiangzuo,ziyou)
      }
      console.log("志愿",zhiyuan)
      console.log("社团",shetuan)
      console.log("讲座",jiangzuo)
      console.log("自由",ziyou)
      console.log("全",card)
      that.setData({
        card,
      })
    })
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    showView1: (options.showView1 == "true" ? true : false)
  },
  onChangeShowState1: function () {
    var that = this;
    that.setData({
      showView1: (!that.data.showView1)
    })
  },
})